package com.quanyan.financialSystem.web.place;


import com.alibaba.fastjson.JSON;
import com.quanyan.api.APIResponse;
import com.quanyan.common.Plugin.PageObj;
import com.quanyan.common.utils.StringUtil;
import com.quanyan.financialSystem.entity.vo.req.ReqCardMember;
import com.quanyan.financialSystem.entity.vo.req.ReqPlaceProfitReport;
import com.quanyan.financialSystem.entity.vo.resp.RespCardMember;
import com.quanyan.financialSystem.service.place.BranchPlaceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author xian-guo
 * @email 498152332@qq.com
 * @date 2016/9/21.
 */
@RestController
@RequestMapping(value = "/admin/api/financial/place")
public class BranchPlaceController {

    private Logger logger = LoggerFactory.getLogger(BranchPlaceController.class);

    @Autowired
    private BranchPlaceService branchPlaceService;

    /**
     * 分管报表
     * @param reqPlaceProfitReport
     * @return
     */
    @RequestMapping(value = "getBranchPlace", method = RequestMethod.POST)
    public APIResponse<Map<String,Object>> getBranchPlace(@RequestBody  ReqPlaceProfitReport reqPlaceProfitReport){
        logger.debug("getBranchPlace--------->>>>"+ JSON.toJSONString(reqPlaceProfitReport));
        Map<String,Object> paramMap=new HashMap<>();
        int cityId=reqPlaceProfitReport.getCityId();
        if (cityId!=0){//标示有搜索城市条件
            paramMap.put("cityId",cityId);
        }
        if (!StringUtil.isBlankOrNull(reqPlaceProfitReport.getTypeFor())){
            paramMap.put("placeIdOrName",reqPlaceProfitReport.getTypeFor());//搜索场馆编号或场馆名称
        }
        paramMap.put("pageNum",reqPlaceProfitReport.getPageNum() * reqPlaceProfitReport.getPageSize());
        paramMap.put("pageSize",reqPlaceProfitReport.getPageSize());
        paramMap.put("startTime",reqPlaceProfitReport.getStartDate());
        paramMap.put("endTime",reqPlaceProfitReport.getEndDate());
        int impor=reqPlaceProfitReport.getImpor();
        if(impor==1){//导出excel表格
            paramMap.put("impor",impor);
            return branchPlaceService.getBranchPlaceImport(paramMap);
        }
        return branchPlaceService.getBranchPlace(paramMap);
    }

    /**
     * 会员流水报表
     * @param reqCardMember
     * @return
     */
    @RequestMapping(value = "getCardMember", method = RequestMethod.POST)
    public APIResponse<PageObj<List<RespCardMember>>> getCardMemberList(@RequestBody ReqCardMember reqCardMember){
        Map<String,Object> paramMap=new HashMap<>();
        Integer cityId =reqCardMember.getCityId();
        if (cityId!=0){//0标示搜索所有城市
            paramMap.put("cityId",cityId);
        }
        int cateId=reqCardMember.getCategoryId();
        if (cateId!=0){//类别
            paramMap.put("categoryId",cateId);
        }
        if (!StringUtil.isBlankOrNull(reqCardMember.getPlaceIdOrName())){
            paramMap.put("placeIdOrName",reqCardMember.getPlaceIdOrName());//搜索场馆编号或场馆名称
        }
        if (!StringUtil.isBlankOrNull(reqCardMember.getInnerCardNo())){//会员卡号
            paramMap.put("innerCardNo",reqCardMember.getInnerCardNo());
        }
        int src=reqCardMember.getSrc();
        if (src!=0){//业务类型
            paramMap.put("src",src);
        }
        int payType=reqCardMember.getPayType();
        if (payType!=-1){//支付方式
            paramMap.put("payType",payType);
        }
        int platForm=reqCardMember.getPlatform();
        if (platForm!=0){//销售渠道
            if(platForm==6){
                paramMap.put("and_ios",platForm);
            }else{
                paramMap.put("platform",platForm);
            }
        }
        if (!StringUtil.isBlankOrNull(reqCardMember.getOrderNo())){//订单号
            paramMap.put("orderNo",reqCardMember.getOrderNo());
        }
        if (!StringUtil.isBlankOrNull(reqCardMember.getMobile())){//手机号
            paramMap.put("mobile",reqCardMember.getMobile());
        }
        if (!StringUtil.isBlankOrNull(reqCardMember.getUserName())){//客户名称
            paramMap.put("userName",reqCardMember.getUserName());
        }
        if (reqCardMember.getImpor()==1){//导出excel
            paramMap.put("impor",1);
        }
        paramMap.put("pageNum",reqCardMember.getPageNum() * reqCardMember.getPageSize());
        paramMap.put("pageSize",reqCardMember.getPageSize());
        paramMap.put("startTime",reqCardMember.getStartTime());
        paramMap.put("endTime",reqCardMember.getEndTime());
        return branchPlaceService.getCardMemberList(paramMap);
    }
}
